import 'package:flutter/material.dart';

main()=>runApp(MyApp());

class MyApp extends StatelessWidget{

  //组件封装

  Widget build(BuildContext context){
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("组件练习"),

        ),
        body: IconContainer(Icons.ac_unit,color:Colors.blue,size: 50),
      ),
    );
  }
}
//封装组件
class IconContainer extends StatelessWidget{
  //可选参数
  double size=32.0;
  Color color = Colors.red;
  //必填参数
  IconData icon;
  IconContainer(this.icon,{this.color,this.size});

  Widget build(BuildContext context){
    return Container(
      height: 100,
      width: 100,
      color: Colors.red,
      child: Center(
        child: Icon(this.icon,size: this.size,color: this.color,),
      ),
    );
  }
}